<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>发布博文-MyBlog</title>
    <style>
        .content{
            width: 600px;
            height: 200px;
        }
        .error{
            font-size: 12px;
            color: red;
        }
    </style>
    <script src="https://cdn.bootcss.com/jquery/2.1.2/jquery.min.js"></script>
    <script>

        function check(){

            //初始化，清空报错信息
            $("#err_blog_title").html('');
            $("#err_blog_content").html('');

            //验证发布文章的数据

            if ($("#blog_title").val() == "") {
                $("#err_blog_title").html('提示：请填写文章标题！');
                $("#blog_title").focus();
                return false;
            }

            if ($("#blog_content").val() == "") {
                $("#err_blog_content").html('提示：请填写文章内容！');
                $("#blog_content").focus();
                return false;
            }


        }

    </script>

    <meta charset="UTF-8">
    <title>碎言碎语-个人博客</title>
    <meta name="keywords" content="个人博客" />
    <meta name="description" content="" />
    <link rel="stylesheet" href="css/index.css"/>
    <link rel="stylesheet" href="css/style.css"/>
    <script type="text/javascript" src="js/jquery1.42.min.js"></script>
    <script type="text/javascript" src="js/jquery.SuperSlide.2.1.1.js"></script>
    <!--[if lt IE 9]>
    <script src="js/html5.js"></script>
    <![endif]-->
</head>
<body>
<!--header start-->
<div id="header">
    <h1>个人博客</h1>
    <p>青春是打开了,就合不上的书。人生是踏上了，就回不了头的路，爱情是扔出了，就收不回的赌注。</p>
    <div id="nav">
        <ul>
            <li><a href="index.html">首页</a></li>
            <li><a href="about.html">关于我</a></li>
            <li><a href="add_blog.php">碎言碎语</a></li>
            <li><a href="changePwd.php">修改密码</a></li>
            <li><a href="xc.html">相册展示</a></li>
            <li><a href="learn.html">学无止境</a></li>
            <li><a href="list.php">文章列表</a></li>
            <div class="clear"></div>
        </ul>
    </div>
</div>
<!--header end-->
<!--content start-->
<div id="say">
    <div class="weizi">
        <div class="wz_text">当前位置：<a href="#">首页</a>><h1><div>

                    <form id="form" action="add_blog.php?act=adding" method="post" onsubmit="return check();">

                        <p>
                            文章标题：<input type="text" name="blog_title" id="blog_title">
                            <label id="err_blog_title" class="error"></label>
                        </p>

                        <p>
                            文章内容：
                            <textarea name="blog_content" id="blog_content" class="content"></textarea>
                            <label id="err_blog_content" class="error"></label>
                        </p>

                        <p>
                            <button>发布文章</button>
                            <button type="button" onclick="window.location.href='list.php';">取消发布</button>
                        </p>

                    </form>

                </div></h1></div>
    </div>








</div>

<!--content end-->
<!--footer-->

<!--footer end-->
<script type="text/javascript">jQuery(".lanmubox").slide({easing:"easeOutBounce",delayTime:400});</script>
<script  type="text/javascript" src="js/nav.js"></script>
<?php

//连接数据库
include 'inc/conn.php';

//验证用户登陆
include 'inc/checkSesion.php';



if ($_GET['act'] === 'adding') {

    //发布文章的操作

    $blog_title = $_POST['blog_title'];
    $blog_content = $_POST['blog_content'];

    if (empty($blog_title) || empty($blog_content)) {
        die("<script>alert('提示：内容有误！');history.back();</script>");
    }

    $sqlAdd = "INSERT INTO blog_info (blog_title, blog_content, add_time) VALUES('".htmlspecialchars($blog_title, ENT_QUOTES)."', 
    '".htmlspecialchars($blog_content, ENT_QUOTES)."', ".time().") ";

    $resAdd = mysqli_query($conn, $sqlAdd);

    if (!$resAdd) {
        die("<script>alert('提示：内容有误！');history.back();</script>");
    }

    echo "<script>alert('文章发布成功！'); window.location.href='list.php';</script>";

}

?>








</body>
</html>